package com.jgp.attachment.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.servlet.MultipartProperties;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import javax.servlet.MultipartConfigElement;


/**
 * 项目   parent
 * 作者   loufei
 * 时间   2018/4/27
 */
@Order(400)
@Configuration
public class AttachmentConfiguration {

    @Autowired
    private MultipartProperties multipartProperties;
    
    @Bean
    public MultipartConfigElement multipartConfigElement() {

        MultipartConfigFactory factory = new MultipartConfigFactory();
        // 设置文件大小限制 ,超出设置页面会抛出异常信息，
        // 这样在文件上传的地方就需要进行异常信息的处理了;
        factory.setMaxFileSize(multipartProperties.getMaxFileSize()); // KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize(multipartProperties.getMaxRequestSize());
        factory.setFileSizeThreshold(multipartProperties.getFileSizeThreshold());
        //factory.setLocation(docProperties.getLocalTempDir());
        // Sets the directory location where files will be stored.
        // factory.setLocation("路径地址");
        return factory.createMultipartConfig();
    }
}
